package project.euler.honk.problem.to100;

import java.math.BigInteger;

public final class Problem65 {
	
	private static int getDigitalSum(BigInteger number) {
		char[] chars = number.toString().toCharArray();
		int sum = 0;
		for (int i = 0; i < chars.length; i++) {
			sum += chars[i] - '0';
		}
		return sum;
	}
	
	public static int solve() { 
		BigInteger d = BigInteger.ONE;
		BigInteger n = BigInteger.valueOf(2);
		 
		for (int i = 2; i <= 100; i++) {
		    BigInteger temp = d;
		    int c = (i % 3 == 0) ? 2 * (i / 3) : 1;
		    d = n;
		    n = d.multiply(BigInteger.valueOf(c)).add(temp);
		}
		return getDigitalSum(n);
	}
	
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		int count = solve();
		long end = System.currentTimeMillis();
		System.out.println("Result: " + count + " Time: " + (end - start));
	}

}
